﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CCFlyAction : SSAction
{
	// 水平和垂直两个方向速度
	public float speedX;
	public float speedY;

	public static CCFlyAction GetSSAction(float sx, float sy){
		CCFlyAction action = ScriptableObject.CreateInstance<CCFlyAction> ();
		action.speedX = sx;
		action.speedY = sy;
		return action;
	}

	public override void Update ()
	{
		// 飞碟已被摧毁
		if (this.gameobject.activeSelf == false) {
			Debug.Log("1 destory!");
			this.destory = true;
			this.callback.SSActionEvent(this);
			return;
		}
		Vector3 vector3 = Camera.main.WorldToScreenPoint(this.transform.position);

		// 飞碟是否飞出屏幕外
		if (vector3.x<-100 || vector3.x>Camera.main.pixelWidth + 100 || vector3.y<-100 || vector3.y>Camera.main.pixelHeight + 100)
		{
			Debug.Log("2 destory!");
			this.destory = true;
			this.callback.SSActionEvent(this);
			return;
		}
		transform.position += new Vector3(speedX, speedY, 0) * Time.deltaTime * 2;
	}

	public override void Start () {
	}
}

